package com.edu.convert;


import com.edu.bean.User;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

// 字符串转换成用户的转换器  username-password-age

public class MyStringToUserConverter implements Converter<String, User> {

    @Override
    public User convert(String source) {
        System.out.println(source);
        User user = new User();
        String[] strs =source.split("-");
        String username = strs[0];
        String password = strs[1];
        int userAge = Integer.parseInt(strs[2]);
        user.setUsername(username);
        user.setPassword(password);
        user.setUserAge(userAge);
        return user;
    }
}
